<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/16
  Time: 21:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑科目信息</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/admin.css">
</head>
<body>
<div style="padding: 15px;">
    <form id="fo" class="bs-example bs-example-form" role="form" method='post' enctype="multipart/form-data">
        <div class="input-group">
            <span class="input-group-addon">科目名称</span>
            <input type="text" name='name' class="form-control" placeholder="请输入科目名称" value=''>
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">藏语科目名称</span>
            <input type="text" name='zname' class="form-control" placeholder="请输入藏语科目名称" value=''>
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">考试时间</span>
            <input type="number" name='longtime' class="form-control" placeholder="请输入考试时间" value=''>
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">考试题量</span>
            <input type="number" name='number' class="form-control" placeholder="请输入考试题量" value=''>
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">科目图标</span>
            <span class="input-group-addon mg" style="background-color: #fff; border-right: none; width: 200px;">
					<%--<a href="/upload/ico/7671496912796841.png" title="查看大图" target="_blank"><img src="/upload/ico/7671496912796841.png" style="width: 20px;"></a>--%>
				</span>
            <input type="file" name='courseImg' class="form-control"  placeholder="请选择图标文件">
            <input type="hidden" name="id" value=''>
        </div>
        <br>
        <button class="btn btn-primary btn-lg btn-block" type="button" onclick="ValidForm()">提交保存</button>
    </form>
</div>
</body>
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>
<script type="text/javascript">
    function ValidForm() {
        var name=$('input[name=name]').val(),
            longtime=$('input[name=longtime]').val(),
            number=$('input[name=number]').val(),
            id=$('input[name=id]').val();
        if(!name){
            layer.msg('请输入科目名称',{icon : 2,time:1000});
            $('input[name=name]').focus();
            return false;
        }
        if(!longtime || longtime<=0){
            layer.msg('请输入考试时间',{icon : 2,time:1000});
            $('input[name=longtime]').focus();
            return false;
        }
        if(!number || number<=0){
            layer.msg('请输入考试题量',{icon : 2,time:1000});
            $('input[name=number]').focus();
            return false;
        }
        if(!id){
            layer.msg('参数错误',{icon : 2,time:1000});
            setTimeout(function(){top.location.reload();},1000);
            return false;
        }
        var formData = new FormData($("#fo")[0]);
        $.ajax({
            async: false,
            cache: false,
            type: "post",
            data: formData,
            url: '/course/fix',
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (json) {
                if (json.status == "success") {
                    layer.msg('修改成功', {icon: 1, time: 1000});
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                }
            },
            error: function () {
                layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
            }
        });
    }
</script>
</html>
